//index.js
//获取应用实例
const app = getApp()
const api = require('../../utils/interface.js');
Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    whose: ["/images/duola2.png", "/images/duola2.png"],
    viewCount: 0,
    viewList: [],
    userId: 0,
    banners: []

  },
  onLoad: function() {
    this.get_user_info();
    this.get_banner();
  },
  getUserInfo: function(e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  wdgz: function() {
    wx.navigateTo({
      url: '../wdgz/wdgz?id=' + this.data.userInfo.Id
    })
  },
  grzy: function() {
    wx.navigateTo({
      url: '../grzy/grzy?id=' + this.data.userInfo.Id
    })
  },
  wdfs: function() {
    wx.navigateTo({
      url: '../wdfs/wdfs?id=' + this.data.userInfo.Id
    })
  },
  whosee: function() {
    wx.navigateTo({
      url: '../whosee/whosee?id=' + this.data.userInfo.Id
    })
  },
  bjzl: function() {
    wx.navigateTo({
      url: '../bjzl/bjzl'
    })
  },
  showModal: function() {
    this.bindCall()
  },
  hideModal: function() {
    // 隐藏遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
    })
    setTimeout(function() {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export(),
        showModalStatus: false
      })
    }.bind(this), 200)
  },
  get_user_info: function() {
    var that = this;
    app.Post(api.wxapp.personal_data, {}, function(res) {
      if (res.code == 1) {
        that.setData({
          userInfo: res.data,
        });
      } else {
        app.WxAlert(res.msg);
      }
    });
  },
  bindCall: function() {
    wx.makePhoneCall({
      phoneNumber: "0519-85808998"
    });
  },
  //获取banan
  get_banner: function() {
    var that = this;
    app.Get(api.wxapp.get_banner, {}, function(res) {
      if (res.code == 1) {
        that.setData({
          banners: res.data.list,
        });
      } else {
        app.WxAlert(res.msg);
      }
    });
  },
  bindurl: function(e) {
    console.log(e);
    wx.navigateTo({
      url: 'webLink?url=' + e.currentTarget.dataset.url,
    })
  }
})